function forEach(array, fn) {
  for (let i = 0; i < array.length; i++) {
    const element = array[i]
    fn(element, i)
  }
}
const arr = [1, 2, 3, 4, 5]

forEach(arr, function (item, i) {
  console.log(item, i)
})

function filter(array, fn) {
  const result = []
  for (let i = 0; i < array.length; i++) {
    const elm = array[i]
    if (fn(elm)) {
      result.push(elm)
    }
  }
  return result
}

console.log(filter(arr, item => item >= 3))
